var add,edit,$formData = $('#formData');
require(['select2', 'validator','date','layout'], function() {
	$('form').initForm();
	add = function(fn) {
		var result = $.validator($formData);
		 if(result&&checkPostData()){
			 $.ajaxExt({
					url : "/reportCarMainteDetail/saveOrUptMaintenanceInfo.htm",
					data : postData
				}).done(function(data){
					fn();
				});
         }
	}
	
	edit = function() {
		var result = $.validator($formData);
		if(result){
			$.ajaxExt({
				url : "/reportCarMainteDetail/uptMaintenRmndrSetInfo.htm",
				data : $formData.getValues()
			}).done(function(data){
				getEditDialog().dialog('close');
				reloadGridData();
			});
		}
	}
	
	setVal = function (maintenId){
		$.ajaxExt({
			url :"/reportCarMainteDetail/getMaintenanceInfoById.htm",
			data : {'maintenId' : maintenId}
		}).done(function(data){
			$formData.setValues(data);
		});
	}
	reset = function (){
		$formData.reset();
	}
	
	function checkPostData(){
		var type = commonFun.getLeftTreeCurrentTreeType();
		if(type=='DRIVER'){
			type='CAR'
		}
		var carIds = commonFun.getLeftTreeCheckedNodes(type);
        if (carIds==null||carIds.length!=1) {
            $.messager.alert("提示", "请选择车辆且仅能新增一辆!", "warning");
            return false;
        }
       postData=$formData.getValues();
       postData.carId=carIds.toString();
		return true;
	};
	
})